interface MyNewType {
    (Factory: Function, ...rest: any[]): any
}

const myNew: MyNewType = (Factory, ...rest) => {
    let newObject = Object.create(Factory.prototype)
    let result = Factory.apply(newObject, rest)
    let flag = result && (typeof(result) === 'object' || typeof(result) === 'function') 
    return flag ? result : newObject
}

function User(this: any, name: string) {
    this.name = name
    // return {name: 'zxc'}
}

const obj = myNew(User, 'kaho')
console.log(obj)
export {}